// miniprogram/pages/system/system.js
var app = getApp();
Page({
  
  /**
   * 页面的初始数据
   */
  data: {
    
    //1
    show: false,
    items: [
      { name: 'TASK_STATUS', value: 'TASK_STATUS' },
      { name: 'RUNNING_STATUS', value: 'RUNNING_STATUS' },
      { name: 'DOC_TYPE', value: 'DOC_TYPE' },
      { name: 'BUG_LEVEL', value: 'BUG_LEVEL' },
      { name: 'BUG_TYPE', value: 'BUG_TYPE' },
      { name: 'SOLVETASK_STATUS', value: 'SOLVETASK_STATUS' },],
    //1
      //4
        columns: ['任务状态', '运行状态', '工作单据类型', '缺陷等级', '缺陷类型','消缺任务状态'],
      //4
      //2
        checked: true,
      //2
      //3
        value: ''
      //3

  
  },
  //5
  insert(e){
    if (this.data.configCode == null) {
      wx.showModal({
        title: '提示',
        content: '没有选择类型编码？', 
      });
      return;
    }
    if (this.data.descQ == null) {
      wx.showModal({
        title: '提示',
        content: '没有填写描述？',
        
      });
      return;
    }
    if (this.data.isStart == true || this.data.isStart == null) {
      this.data.isStart = 1
    } else if (this.data.isStart == false) {
      this.data.isStart = 2
    }
    if (this.data.configName == null){
      this.data.configName='任务状态';
    }
    console.log("1", this.data.configCode)
    console.log("2", this.data.isStart)
    console.log("3", this.data.descQ)
    console.log("4", this.data.configName)
    wx.request({
      url: getApp().appData.site+'/accp/psSystemconfig/insert',
      data:{
        configCode: this.data.configCode,
        isStart: this.data.isStart,
        descQ: this.data.descQ,
        configName: this.data.configName
      },
      success: (res) => {
        console.log(res)
        wx.redirectTo({
          url: '/pages/system/system',
        })
      }
    })

  },
  //5
  
  //3
  onChange3(event) {
    // event.detail 为当前输入的值
    console.log(event.detail.value);
    this.setData({
      descQ:event.detail.value
    })
  },
  //3

  //2
  onChange2(e) {
    wx.showModal({
      title: '提示',
      content: '是否启用？',
      success: res => {
        if (res.confirm) {
            this.setData({ 
              checked: e.detail, 
              isStart:e.detail
            });
          console.log(this.data.checked)
          console.log(this.data.isStart)
        }
      }
    });
  },
  //2

  //4
  onConfirm(event) {    
    const { picker, value, index } = event.detail;
    wx.showToast({
      title: `当前值：${value}, 当前索引：${index}`,
    })
    console.log(event.detail.value)
    this.setData({
      configName: event.detail.value
    })
  },

  onCancel() {
    Toast('取消');
  },//4






  //1
  /**
   * 组件的方法列表
   */
  onChange(event) {
    this.setData({
      sex: event.detail
    });
  },

  /*点击变色*/
  click: function (e) {
    var id = e.currentTarget.dataset.id
    var that = this
    that.setData({
      id: id
    })
  },
  onLoad: function (options) {
    var that = this
    that.setData({
      value: 'show'
    })
  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    var that = this
    that.setData({
      configCode: e.detail.value
    })
    console.log(this.data.configCode)
  },
  toggleDialog() {
    this.setData({
      showDialog: !this.data.showDialog
    });
  },
  freeBack: function () {
    var that = this
    if (this.data.value == 'show') {
      wx.showModal({
        title: '提示',
        content: '你没有选择任何内容',
      })
    }
    that.setData({
      showDialog: !this.data.showDialog
    })
  },
  freetoBack: function () {
    var that = this
    wx.showModal({
      title: '提示',
      content: '你没有选择任何内容',
    })
    that.setData({
      showDialog: !this.data.showDialog,
      value: 'null',
      checked: false,
    })
  },
  //1



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})